//
//  RMCheckButton.m
//  RMLKBase
//
//  Created by 任科玮 on 2016/11/24.
//  Copyright © 2016年 任科玮. All rights reserved.
//

#import "RMCheckButton.h"

@implementation RMCheckButton


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _ischeck = unselectCheck;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addTarget:self action:@selector(tapCheck) forControlEvents:UIControlEventTouchUpInside];
        self.bounds = CGRectMake(0, 0, 25, 25);
    }
    return self;
}

- (void)tapCheck
{
    if (_ischeck == unselectCheck)
    {
        _ischeck = selectCheck;
        [self setTitle:@"✔️" forState:UIControlStateNormal];
    }
    else
    {
        _ischeck = unselectCheck;
        [self setTitle:@"" forState:UIControlStateNormal];
    }
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}

- (void)drawRect:(CGRect)rect {
    
//    CGRect bounds = rect;
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色
    CGContextSetLineWidth(context, 2.0);
    CGContextAddRect(context, CGRectMake(2.5, 2.5, 20, 20));
    CGContextStrokePath(context);
    
    [super drawRect:rect];
}

@end
